package com.transaction.manage.controller;

import com.transaction.common.base.BaseController;
import com.transaction.common.base.PageInfo;
import com.transaction.common.util.ParamsUtil;
import com.transaction.manage.model.dto.*;
import com.transaction.manage.model.vo.FundOpenDateVo;
import com.transaction.manage.service.BusinessParamsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/businessParams")
@ApiIgnore
public class BusinessParamsController extends BaseController {

    private static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private BusinessParamsService businessParamsService;


    /**-----------------------------------------fund-info-----------------------------------------------**/

    /**
     * 查询产品信息集合
     * @param request
     * @return
     */
    @GetMapping("/selectFundInfoList")
    public Object selectFundInfoList(HttpServletRequest request){
        FundInfo fundInfo = ParamsUtil.getBeanParam(new FundInfo(),request);
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        List<FundInfo> fundInfoList = businessParamsService.selectFundInfoList(fundInfo,pageInfo);
        pageInfo.setPageResult(fundInfoList);
        return pageInfo;
    }

    /**
     * 保存产品信息
     * @param fundInfo 产品信息
     * @return
     */
    @PostMapping("/saveFundInfo")
    public Object saveFundInfo(@RequestBody FundInfo fundInfo){
        businessParamsService.saveFundInfo(fundInfo);
        return retResultVo("保存成功！");
    }

    /**
     * 删除产品
     * @param fundInfo
     * @return
     */
    @PostMapping("/deleteFundInfo")
    public Object deleteFundInfo(@RequestBody FundInfo fundInfo){
        businessParamsService.deleteFundInfo(fundInfo.getChannelCode(),fundInfo.getFundCode());
        return retResultVo("删除成功！");
    }

    /**
     * 复核产品
     * @param fundInfo
     * @return
     */
    @PostMapping("/checkFundInfo")
    public Object checkFundInfo(@RequestBody FundInfo fundInfo){
        businessParamsService.checkFundInfo(fundInfo.getChannelCode(),fundInfo.getFundCode());
        return retResultVo("复核成功！");
    }

    /**
     * 查询fundInfoModal页面所有的下拉
     * @return
     */
    @GetMapping("/selectFundInfoModalAllCombobox")
    public Object selectFundInfoModalAllCombobox(){
        Map<String,Object> map = businessParamsService.selectFundInfoModalAllCombobox();
        return retResultVo(map);
    }

    /**-----------------------------------------fund-info-----------------------------------------------**/



    /**-----------------------------------------fund-relation-----------------------------------------------**/

    /**
     * 查询产品关系信息集合
     * @param request
     * @return
     */
    @GetMapping("/selectFundRelationList")
    public Object selectFundRelationList(HttpServletRequest request){
        FundRelation fundRelation = ParamsUtil.getBeanParam(new FundRelation(),request);
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        List<FundRelation> fundRelationList = businessParamsService.selectFundRelationList(fundRelation,pageInfo);
        pageInfo.setPageResult(fundRelationList);
        return pageInfo;
    }

    /**
     * 保存产品关系信息
     * @param fundRelation 产品关系信息
     * @return
     */
    @PostMapping("/saveFundRelation")
    public Object saveFundRelation(@RequestBody FundRelation fundRelation){
        businessParamsService.saveFundRelation(fundRelation);
        return retResultVo("保存成功！");
    }

    /**
     * 删除产品关系
     * @param fundRelation
     * @return
     */
    @PostMapping("/deleteFundRelation")
    public Object deleteFundRelation(@RequestBody FundRelation fundRelation){
        businessParamsService.deleteFundRelation(fundRelation.getChannelCode(),fundRelation.getFundCode(),fundRelation.getTaFundCode());
        return retResultVo("删除成功！");
    }

    /**
     * 复核产品关系
     * @param fundRelation
     * @return
     */
    @PostMapping("/checkFundRelation")
    public Object checkFundRelation(@RequestBody FundRelation fundRelation){
        businessParamsService.checkFundRelation(fundRelation.getChannelCode(),fundRelation.getFundCode(),fundRelation.getTaFundCode());
        return retResultVo("复核成功！");
    }

    /**
     * 查询fundRelationModal页面所有的下拉
     * @return
     */
    @GetMapping("/selectFundRelationModalAllCombobox")
    public Object selectFundRelationModalAllCombobox(){
        Map<String,Object> map = businessParamsService.selectFundRelationModalAllCombobox();
        return retResultVo(map);
    }

    /**-----------------------------------------fund-relation-----------------------------------------------**/


    /**-----------------------------------------fund-yield-----------------------------------------------**/

    /**
     * 查询产品收益率信息集合
     * @param request
     * @return
     */
    @GetMapping("/selectFundYieldList")
    public Object selectFundYieldList(HttpServletRequest request){
        FundYield fundYield = ParamsUtil.getBeanParam(new FundYield(),request);
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        List<FundYield> fundYieldList = businessParamsService.selectFundYieldList(fundYield,pageInfo);
        pageInfo.setPageResult(fundYieldList);
        return pageInfo;
    }

    /**
     * 保存产品收益率信息
     * @param fundYield 产品收益率信息
     * @return
     */
    @PostMapping("/saveFundYield")
    public Object saveFundYield(@RequestBody FundYield fundYield){
        businessParamsService.saveFundYield(fundYield);
        return retResultVo("保存成功！");
    }

    /**
     * 删除产品收益率
     * @param fundYield
     * @return
     */
    @PostMapping("/deleteFundYield")
    public Object deleteFundYield(@RequestBody FundYield fundYield){
        businessParamsService.deleteFundYield(fundYield.getId());
        return retResultVo("删除成功！");
    }

    /**
     * 复核产品收益率
     * @param fundYield
     * @return
     */
    @PostMapping("/checkFundYield")
    public Object checkFundYield(@RequestBody FundYield fundYield){
        businessParamsService.checkFundYield(fundYield.getId());
        return retResultVo("复核成功！");
    }

    /**
     * 查询fundYieldModal页面所有的下拉
     * @return
     */
    @GetMapping("/selectFundYieldModalAllCombobox")
    public Object selectFundYieldModalAllCombobox(){
        Map<String,Object> map = businessParamsService.selectFundYieldModalAllCombobox();
        return retResultVo(map);
    }

    /**-----------------------------------------fund-yield-----------------------------------------------**/


    /**-----------------------------------------fund-trans-rate-----------------------------------------------**/

    /**
     * 查询产品交易费率信息集合
     * @param request
     * @return
     */
    @GetMapping("/selectFundTransRateList")
    public Object selectFundRYieldList(HttpServletRequest request){
        FundTransRate fundTransRate = ParamsUtil.getBeanParam(new FundTransRate(),request);
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        List<FundTransRate> fundTransRateList = businessParamsService.selectFundTransRateList(fundTransRate,pageInfo);
        pageInfo.setPageResult(fundTransRateList);
        return pageInfo;
    }

    /**
     * 保存产品交易费率信息
     * @param fundTransRate 产品交易费率信息
     * @return
     */
    @PostMapping("/saveFundTransRate")
    public Object saveFundTransRate(@RequestBody FundTransRate fundTransRate){
        businessParamsService.saveFundTransRate(fundTransRate);
        return retResultVo("保存成功！");
    }

    /**
     * 删除产品交易费率
     * @param fundTransRate
     * @return
     */
    @PostMapping("/deleteFundTransRate")
    public Object deleteFundTransRate(@RequestBody FundTransRate fundTransRate){
        businessParamsService.deleteFundTransRate(fundTransRate.getId());
        return retResultVo("删除成功！");
    }

    /**
     * 复核产品交易费率
     * @param fundTransRate
     * @return
     */
    @PostMapping("/checkFundTransRate")
    public Object checkFundTransRate(@RequestBody FundTransRate fundTransRate){
        businessParamsService.checkFundTransRate(fundTransRate.getId());
        return retResultVo("复核成功！");
    }

    /**
     * 查询fundTransRateModal页面所有的下拉
     * @return
     */
    @GetMapping("/selectFundTransRateModalAllCombobox")
    public Object selectFundTransRateModalAllCombobox(){
        Map<String,Object> map = businessParamsService.selectFundTransRateModalAllCombobox();
        return retResultVo(map);
    }
    /**-----------------------------------------fund-trans-rate-----------------------------------------------**/


    /**-----------------------------------------fund-open-date-----------------------------------------------**/

    /**
     * 查询产品开放交易日期
     * @return
     */
    @RequestMapping("/selectFundOpenDates")
    public Object selectFundOpenDates(HttpServletRequest request){
        FundOpenDate fundOpenDate = ParamsUtil.getBeanParam(new FundOpenDate(),request);
        List<FundOpenDate> fundOpenDateList = businessParamsService.selectFundOpenDates(fundOpenDate);
        return retResultVo(fundOpenDateList);
    }

    /**
     * 查询产品交易日页面下拉
     * @return
     */
    @RequestMapping("/selectFundOpenDateAllCombobox")
    public Object selectFundOpenDateAllCombobox(){
        Map<String,Object> map = businessParamsService.selectFundOpenDateAllCombobox();
        return retResultVo(map);
    }

    /**
     * 保存产品交易日
     * @param fundOpenDateVo 保存的产品交易日对象
     * @return
     */
    @RequestMapping("/saveFundOpenDates")
    public Object saveFundOpenDates(@RequestBody FundOpenDateVo fundOpenDateVo){
        businessParamsService.saveFundOpenDates(fundOpenDateVo);
        return retResultVo("保存成功！");
    }


    /**-----------------------------------------fund-open-date-----------------------------------------------**/

}
